package rhc.discribute.node.connecter;

import rhc.discribute.node.connecter.impl.ZKPathLockData;
import rhc.discribute.node.host.Host;
import rhc.discribute.node.sendMessage.SendMessageCallback;

/**提供给外部使用的接口
 * @author rhc
 *
 */
public interface Connecter {

	/**发送消息到一个主机
	 * @param host
	 * @param message
	 * @throws Exception
	 */
	void sendMessageToHost(Host host,String message,SendMessageCallback callback,boolean wait) throws Exception;
	
	/**尝试获取该路径锁，如果该路径锁已被持有则直接返回false，否则获取锁后返回false
	 * @param lockPath
	 * @return
	 * @throws Exception
	 */
	ZKPathLockData tryAcquire(String lockPath) throws Exception;
	
	/**尝试获取路径锁，如果该路径锁已被持有则尝试获取并等待milis毫秒，如果在这中间获取到则返回true，否则放弃获取返回false
	 * @param lockPath
	 * @param milis
	 * @return
	 * @throws Exception
	 */
	ZKPathLockData tryAcquire(String lockPath,long waitSeconds) throws Exception;
	
	/**获取锁，直到获取到再返回
	 * @param lockPath
	 * @return
	 * @throws Exception
	 */
	ZKPathLockData acquire(String lockPath) throws Exception;
	
	/**释放锁
	 * @param lockPath
	 * @throws Exception
	 */
	void release(ZKPathLockData lockData) throws Exception;
}
